package br.ita.comp.ces22.quiz.core;

import java.util.ArrayList;

import br.ita.comp.ces22.quiz.core.dao.DAOFactory;
import br.ita.comp.ces22.quiz.core.dao.UserDAO;
import br.ita.comp.ces22.quiz.domain.User;

public class ObserverManager {
	private static ArrayList<User> observerList;
	private static UserDAO userDao = null;

	public static void notifyObservers(Exception ex){
		updateObserverList();
		
		for(User observer: observerList){
			observer.update(observer.getEmail(), observer.getLogin() + " " + ex.getStackTrace()[0].toString());
		}
	}
	
	private static void updateObserverList(){
		if (userDao == null) {
			userDao = DAOFactory.getDAOFactory().getUserDAO();
		}
		observerList = (ArrayList<User>) userDao.getObservers(); 
	}
}
